package com.example.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.dao.UserDaoImpl;
import com.example.bean.UserBean;
import java.util.List;

@RestController
public class MySQLController {

    @Autowired
    private UserDaoImpl userDaoImpl;

    @RequestMapping(value = "/all",method = RequestMethod.GET)

    public String findAll(){
        List<UserBean> list = userDaoImpl.findAll();
        for (UserBean user : list) {
            System.out.println(user.getUsername()+" "+user.getPassword());
        }
        return "查询所有！";
    }

    @RequestMapping(value = "add",method = RequestMethod.GET)
    public String add(UserBean user){//@ModelAttribute("user") User user
        user.setUsername("海龟");
        user.setPassword("21");
        System.out.println(user.getUsername()+"接收参数.....");
        boolean flag = userDaoImpl.addUser(user);
        System.out.println("......"+flag+".....");
        return "添加";
    }

    @RequestMapping(value = "/del",method = RequestMethod.GET)
    public String deleteByUser(String name){
        name = "海龟";
        boolean flag = userDaoImpl.deleteByUserName(name);
        System.out.println(flag);
        return "根据name删除";
    }

    @RequestMapping(value = "/update",method = RequestMethod.GET)
    public String update(String name,String password){
        //指定名字
        name = "wangxingzi";
        //要修改的age
        password = "13";
        System.out.println(userDaoImpl.updateByUserName(name,password));
        return "修改数据";
    }

}
